package ${package.Controller};


import org.springframework.web.bind.annotation.*;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#-- 经常更换：开始 -->
import  ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
<#-- 经常更换：结束 -->
import com.qsn.tool.common.base.PageForm;
import com.qsn.tool.common.base.PageData;
import com.qsn.tool.common.result.Result;

import lombok.extern.slf4j.Slf4j;
import java.util.List;
import javax.annotation.Resource;
<#--import org.springframework.beans.factory.annotation.Autowired;-->

/**
 * ${table.comment!} 前端控制器
 *
 * @author ${author}
 * @date ${date}
 */
@Slf4j
@RestController
@RequestMapping("/${table.entityName?uncap_first}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    @Resource
    private ${table.serviceName} ${table.serviceName?uncap_first};

    /**
     * ${table.comment}分页
     *
     * @param pageForm 分页参数及查询条件
     * @return 分页信息
     */
    @PostMapping("/${table.entityName?uncap_first}/listPage")
    public Result listPage${table.entityName}(@RequestBody PageForm<${table.entityName}> pageForm){
        PageData<${table.entityName}> page = ${table.serviceName?uncap_first}.listPage${table.entityName}(pageForm);
        return Result.success(page);
    }

    /**
     * ${table.comment}列表
     *
     * @param ${table.entityName?uncap_first} 查询条件
     * @return 列表信息
     */
    @PostMapping("/${table.entityName?uncap_first}/list")
    public Result list${table.entityName}(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        List<${table.entityName}> list = ${table.serviceName?uncap_first}.list${table.entityName}(${table.entityName?uncap_first});
        return Result.success(list);
    }

    /**
     * ${table.comment}新增
     *
     * @param ${table.entityName?uncap_first} 新增信息
     * @return 成功或失败
     */
    @PostMapping("/${table.entityName?uncap_first}/insert")
    public Result insert${table.entityName}(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return ${table.serviceName?uncap_first}.insert${table.entityName}(${table.entityName?uncap_first}) ? Result.success() : Result.error("新增信息失败");
    }

    /**
     * ${table.comment}修改
     *
     * @param ${table.entityName?uncap_first} 根据主键修改信息
     * @return 成功或失败
     */
    @PostMapping("/${table.entityName?uncap_first}/updateById")
    public Result update${table.entityName}ById(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return ${table.serviceName?uncap_first}.update${table.entityName}ById(${table.entityName?uncap_first}) ? Result.success() : Result.error("修改信息失败");
    }

    /**
     * ${table.comment}详情
     *
     * @param ${table.entityName?uncap_first} 根据主键获取详情
     * @return ${table.comment}详情
     */
    @PostMapping("/${table.entityName?uncap_first}/getById")
    public Result get${table.entityName}ById(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        ${table.entityName} detail = ${table.serviceName?uncap_first}.get${table.entityName}ById(${table.entityName?uncap_first});
        return Result.success(detail);
    }





}
</#if>